# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection for details
	helper_method :current_user
  
   def authenticated?()
    not session[:user_id].nil?
  end
  
	def current_user
	  @current_user ||= User.find(session[:user_id]) if session[:user_id]
	end
	
	def check_authentication
    return true if authenticated?
      route_to_login "Vous devez être connecté" 
  end
  
  def route_to_login(message = nil)
    flash[:error] = message if message
    session[:original_uri] = request.request_uri if request.get?
    redirect_to login_url
   
  end
  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password
end
